<template>
  <div class="summary-detail">
    <div class="summary-detail__select">
      <div class="summary-detail__select-city">
        <el-select v-model="city" size="mini" @change="changeCity">
          <el-option
            v-for="(item, i) in cityList"
            :key="i"
            :label="item"
            :value="item"
            >
          </el-option>
        </el-select>
      </div>
      <div class="summary-detail__select-zones">
        <el-select v-model="zoneId" size="mini" @change="getData">
          <el-option
            v-for="item in zonesList"
            :key="item.id"
            :label="item.name"
            :value="item.id"
            >
          </el-option>
        </el-select>
      </div>
      <div class="summary-detail__select-date" style="margin-right: 10px">
        <el-date-picker
          v-model="startTime"
          type="month"
          :clearable="false"
          size="mini"
          value-format="yyyy-MM"
          format="yyyy年M月"
          @change="getData">
        </el-date-picker>
      </div>-
      <div class="summary-detail__select-date" style="margin-left: 10px">
        <el-date-picker
          v-model="endTime"
          type="month"
          :clearable="false"
          size="mini"
          value-format="yyyy-MM"
          format="yyyy年M月"
          @change="getData">
        </el-date-picker>
      </div>
    </div>
    <div class="summary-detail__content">
      <ve-histogram ref="chart2" :data="bxData" :judge-width="true" :settings="chartSettings2" :extend="chartExtend2" :width="width" :height="height"></ve-histogram>
      <ve-histogram ref="chart1" :data="bsData"  :judge-width="true" :settings="chartSettings" :extend="chartExtend" :width="width" :height="height"></ve-histogram>
    </div>
     <div class="summary-detail__content">
      <ve-histogram ref="chart3" :data="tsData" :settings="chartSettings3" :extend="chartExtend3" :width="width" :height="height"></ve-histogram>
      <ve-histogram ref="chart4" :data="byData" :settings="chartSettings4" :extend="chartExtend4" :width="width" :height="height"></ve-histogram>
    </div>
  </div>
</template>
<script>
import echarts from 'echarts/lib/echarts'
import { Select, Option, DatePicker } from 'element-ui'
import Histogram from 'v-charts/lib/histogram.common'
import { getKhfwDetailRound, getZonesList} from 'src/api/api'
import { formatDate, formatFontSize, getPreMonth } from 'js/utils'
import storage from 'good-storage'
export default {
  components: {
    [Select.name]: Select,
    [Option.name]: Option,
    [Histogram.name]: Histogram,
    [DatePicker.name]: DatePicker,
  },
  data(){
    return {
      width: '25rem',
      height: '13rem',
      // height: '263px',
      cityList: storage.get('cityList'),
      city: '杭州',
      zonesList: [],
      zoneId: 14,
      startTime: formatDate('yyyy-mm', getPreMonth(5)),
      endTime: formatDate('yyyy-mm', new Date()),
      chartSettings: {
        labelMap: {
          'bsNum': '报事单数',
          'jrbxNum': '报修单数',
          'tsNum': '投诉单数',
          'byNum': '表扬单数',
        },
      },
      chartExtend: {
        title: {
          text: '报事单统计图',
          textStyle: {
            color: '#fff',
            fontSize: formatFontSize(0.12),
          },
          left: '25%',
        },
        legend: {
          show: true,
          textStyle: {
            color: '#fff',
            fontSize: formatFontSize(0.12),
          },
          selectedMode: false,
          right: '20%',
          top: '0',
          itemWidth: formatFontSize(0.15),
          itemHeight: formatFontSize(0.08),
        },
        xAxis: {
          axisLabel: {
            fontSize: formatFontSize(0.12),
            color: '#8EC7DC'
          },
        },
        yAxis: {
          axisLabel: {
            color: '#fff',
            fontSize: formatFontSize(0.1),
          },
          axisLine: {
            show: true,
            lineStyle: {
              color: '#fff',
              opacity: 0.1,
            }
          },
          splitLine: {
            show: true,
            lineStyle: {
              color: '#fff',
              opacity: 0.1,
            }
          },
          // max: 1000,
          splitNumber: 10,
        },
        grid: {  
          left: '0',  
          right: '0',
          top: '20%',
          bottom: '5%',  
        },
        series: {
          barWidth: formatFontSize(0.2),
          label: { 
            show: true, 
            position: 'top',
            color: '#fff',
            fontSize: formatFontSize(0.1),
          },
          itemStyle: {
            color: new echarts.graphic.LinearGradient(
              0, 0, 0, 1,
              [
                  {offset: 0, color: 'rgba(63,255,234,0.82)'},
                  {offset: 1, color: 'rgba(0,126,255,0.2)'}
              ]
            )
          },
        }
      },
      chartSettings2: {
        label: {
          show: false
        },
        labelMap: {
          'bsNum': '报事单数',
          'jrbxNum': '报修单数',
          'tsNum': '投诉单数',
          'byNum': '表扬单数',
        },
      },
      chartExtend2: {
        title: {
          text: '报修单统计图',
          textStyle: {
            color: '#fff',
            fontSize: formatFontSize(0.12),
          },
          left: '25%',
        },
        legend: {
          show: true,
          textStyle: {
            color: '#fff',
            fontSize: formatFontSize(0.12),
          },
          selectedMode: false,
          right: '20%',
          top: '0',
          itemWidth: formatFontSize(0.15),
          itemHeight: formatFontSize(0.08),
        },
        xAxis: {
          axisLabel: {
            fontSize: formatFontSize(0.12),
            color: '#8EC7DC'
          },
        },
        yAxis: {
          axisLabel: {
            color: '#fff',
            fontSize: formatFontSize(0.1),
          },
          axisLine: {
            show: true,
            lineStyle: {
              color: '#fff',
              opacity: 0.1,
            }
          },
          splitLine: {
            show: true,
            lineStyle: {
              color: '#fff',
              opacity: 0.1,
            }
          },
          // max: 1000,
          splitNumber: 10,
        },
        grid: {  
          left: '0',  
          right: '0',
          top: '20%',
          bottom: '5%',  
        },
        series: {
          barWidth: formatFontSize(0.2),
          label: { 
            show: true, 
            position: 'top',
            color: '#fff',
            fontSize: formatFontSize(0.1),
          },
          itemStyle: {
            color: new echarts.graphic.LinearGradient(
              0, 0, 0, 1,
              [
                  {offset: 0, color: 'rgba(255,234,0,0.82)'},
                  {offset: 1, color: 'rgba(255,157,0,0.2)'}
              ]
            )
          },
        }
      },
      chartSettings3: {
        labelMap: {
          'bsNum': '报事单数',
          'jrbxNum': '报修单数',
          'tsNum': '投诉单数',
          'byNum': '表扬单数',
        },
      },
      chartExtend3: {
        title: {
          text: '投诉单统计图',
          textStyle: {
            color: '#fff',
            fontSize: formatFontSize(0.12),
          },
          left: '25%',
        },
        legend: {
          show: true,
          textStyle: {
            color: '#fff',
            fontSize: formatFontSize(0.12),
          },
          selectedMode: false,
          right: '20%',
          top: '0',
          itemWidth: formatFontSize(0.15),
          itemHeight: formatFontSize(0.08),
        },
        xAxis: {
          axisLabel: {
            fontSize: formatFontSize(0.12),
            color: '#8EC7DC'
          },
        },
        yAxis: {
          axisLabel: {
            color: '#fff',
            fontSize: formatFontSize(0.1),
          },
          axisLine: {
            show: true,
            lineStyle: {
              color: '#fff',
              opacity: 0.1,
            }
          },
          splitLine: {
            show: true,
            lineStyle: {
              color: '#fff',
              opacity: 0.1,
            }
          },
          // max: 1000,
          splitNumber: 10,
        },
        grid: {  
          left: '0',  
          right: '0',
          top: '20%',
          bottom: '5%',  
        },
        series: {
          barWidth: formatFontSize(0.2),
          label: { 
            show: true, 
            position: 'top',
            color: '#fff',
            fontSize: formatFontSize(0.1),
          },
          itemStyle: {
            color: new echarts.graphic.LinearGradient(
              0, 0, 0, 1,
              [
                  {offset: 0, color: 'rgba(255,173,186,0.82)'},
                  {offset: 1, color: 'rgba(232,119,137,0.2)'}
              ]
            )
          },
        }
      },
      chartSettings4: {
        labelMap: {
          'bsNum': '报事单数',
          'jrbxNum': '报修单数',
          'tsNum': '投诉单数',
          'byNum': '表扬单数',
        },
      },
      chartExtend4: {
        title: {
          text: '表扬单统计图',
          textStyle: {
            color: '#fff',
            fontSize: formatFontSize(0.12),
          },
          left: '25%',
        },
        legend: {
          show: true,
          textStyle: {
            color: '#fff',
            fontSize: formatFontSize(0.12),
          },
          selectedMode: false,
          right: '20%',
          top: '0',
          itemWidth: formatFontSize(0.15),
          itemHeight: formatFontSize(0.08),
        },
        xAxis: {
          axisLabel: {
            fontSize: formatFontSize(0.12),
            color: '#8EC7DC'
          },
        },
        yAxis: {
          axisLabel: {
            color: '#fff',
            fontSize: formatFontSize(0.1),
          },
          axisLine: {
            show: true,
            lineStyle: {
              color: '#fff',
              opacity: 0.1,
            }
          },
          splitLine: {
            show: true,
            lineStyle: {
              color: '#fff',
              opacity: 0.1,
            }
          },
          // max: 1000,
          splitNumber: 10,
        },
        grid: {  
          left: '0',  
          right: '0',
          top: '20%',
          bottom: '5%',  
        },
        series: {
          barWidth: formatFontSize(0.2),
          label: { 
            show: true, 
            position: 'top',
            color: '#fff',
            fontSize: formatFontSize(0.1),
          },
          itemStyle: {
            color: new echarts.graphic.LinearGradient(
              0, 0, 0, 1,
              [
                  {offset: 0, color: 'rgba(83,237,115,0.82)'},
                  {offset: 1, color: 'rgba(6,124,31,0.2)'}
              ]
            )
          },
        }
      },
      bsData: {
        columns: ['month', 'bsNum'],
        rows: []
      },
      bxData: {
        columns: ['month', 'jrbxNum'],
        rows: []
      },
      tsData: {
        columns: ['month', 'tsNum'],
        rows: []
      },
      byData: {
        columns: ['month', 'byNum'],
        rows: []
      },
    }
  },
  mounted() {
    this._getZonesList()
    this.getData()
  },
  methods: {
    _getZonesList() {
      let params = {
        city: this.city
      }
      getZonesList(params).then(res=> {
        if (res.success === true) {
          this.zonesList = res.data
        }
      })
    },
    getData() {
      let params = {
        city: this.city,
        zoneId: this.zoneId,
        startTime: this.startTime,
        endTime: this.endTime,
      }
      getKhfwDetailRound(params).then(res=>{
        this.bsData.rows = res.data
        this.bxData.rows = res.data
        this.tsData.rows = res.data
        this.byData.rows = res.data
      })
    },
    changeCity() {
      let params = {
        city: this.city
      }
      getZonesList(params).then(res=> {
        if (res.success === true) {
          this.zonesList = res.data
          this.zoneId = res.data[0].id
          this.getData()
        }
      })
    }
  }
}
</script>
<style lang="scss">
.summary-detail {
  padding-bottom: 15px;
  &__select {
    text-align: right;
    padding: 5px 40px 5px 0;
    font-size: 14px;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    color: #AAECFF;
    .el-select, .el-date-editor {
      .el-input__inner {
        // width: 150px;
        border: 0;
        border-radius: 0;
        background:rgba(11,21,58,1);
        box-shadow:1px 1px 0px 0px rgba(255,255,255,0.25), 0px 2px 4px 0px rgba(0, 0, 0, 1);
        color: #AAECFF;
        font-size: 14px;
      }
      .el-input__icon {
        color: #AAECFF;
        font-size: 14px;
      }
    }
    &-zones {
      margin-right: 20px;
      .el-select {
        width: 120px;
      }
    }
    &-city {
      margin-right: 20px;
      .el-select {
        width: 80px;
      }
    }
    &-date {
      // margin-right: 20px;
      .el-date-editor {
        width: 100px;
      }
      .el-input__prefix ,.el-input__suffix{
        display: none;
      }
      .el-input--prefix .el-input__inner {
        padding-left: 5px;
      }
      .el-input--suffix .el-input__inner {
          padding-right: 0px;
      }
    }
  }
  .legend {
    display: flex;
    align-items: center;
    padding-right: 50px;
    .item {
      display: flex;
      align-items: center;
      font-size: 12px;
      padding-right: 50px;
    }
    .square {
      height: 10px;
      width: 23px;
      display: block;
      margin-right: 10px;
      // border: 1px solid red;
    }
  }
  &__content {
    display: flex;
    flex-wrap: nowrap;
    justify-content: space-around;
    // width: 100%;
  }
}
</style>